/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import database_beans.Korisnik;
import database_beans.Role;
import database_beans.Zaposleni;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author stefan
 */
public class UserLoginAndLogout {

    private static UserLoginAndLogout instance;

    private UserLoginAndLogout() {
    }

    public static synchronized UserLoginAndLogout getInstance() {
        if (instance == null) {
            instance = new UserLoginAndLogout();
        }
        return instance;
    }

    public Korisnik login(String usrnm, String pass) {
        Korisnik user = null;
        Session session = Util.getSesion();
        Transaction t = session.beginTransaction();
        Criteria userCriteria = session.createCriteria(Korisnik.class);
        userCriteria.add(Restrictions.eq("ime", usrnm));
        userCriteria.add(Restrictions.eq("lozinka", pass));

        if (!userCriteria.list().isEmpty()) {
            user = (Korisnik) userCriteria.list().get(0);

        }
        t.commit();
        return user;
    }
}
